package com.heima.feigns.fallback;

import com.heima.feigns.ArticleFegin;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ArticleFeignFallback implements FallbackFactory<ArticleFegin> {
    @Override
    public ArticleFegin create(Throwable throwable) {
        return new ArticleFegin() {
            @Override
            public ResponseResult<ApAuthor> findByUserId(Integer id) {
                log.error("参数: {}",id);
                log.error("自媒体 findByUserId 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }

            @Override
            public ResponseResult<ApAuthor> saveApAuthor(ApAuthor apAuthor) {
                log.error("参数: {}",apAuthor);
                log.error("自媒体 saveApAuthor 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }

            @Override
            public ResponseResult<ApArticle> findByArticleId(Long articleId) {
                log.error("参数: {}",articleId);
                log.error("自媒体 findByArticleId 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }
        };
    }
}
